# #include "stdafx.h"  
# #include <cv.h>  
# #include <cxcore.h>  
# #include <highgui.h>  
# #include <iostream>  
# using namespace std;  
#   
# void processFrame(IplImage*& image);  
#   
# int main(int argc, char** argv)   
# {  
#  // ?????????????? ???????? ????? ???????????.  
#  // ? ?????? ?????? - ??? ???????????, ???????????? ??   
#  // ?????? ?? ???????????. 0 ????????, ??? ????  
#  // ??????? ?????? ?????????? ??????. ? ??? ?? ????,  
#  // ??????? ?? ????? ??????????? ?? ????? ?????? :)  
#  CvCapture* capture = 0;  
#  capture = cvCreateCameraCapture(0);  
#  if (!capture)  
#  {  
#   cout << "Initialization failed" << endl;  
#   return EXIT_FAILURE;  
#  }  
#   
#  // ?????? ? GUI ???????? ?? ????????????. ??????????  
#  // ?????????? ????????????? (?? ???????????????? -  
#  // ????????? ????), ?? ???????? ?? ????? ??????????  
#  // ???? ????.  
#  const char *windowName = "First steps with OpenCV";  
#  cvNamedWindow(windowName, CV_WINDOW_AUTOSIZE);  
#   
#  while(true)   
#  {  
#   // ?????????? ?????? ??? ????????? ?????????? ?????  
#   IplImage* frame = cvQueryFrame( capture );  
#   if(!frame)   
#    break;  
#   
#   // processFrame(frame);  
#   
#   // ????????? ??? ????? ? ???? (?? ??????, ??? ?? ???  
#   // ??????????? - ????? ?????????????)  
#   cvShowImage(windowName, frame);  
#   
#   // ?? ??????? ESC - ????? ?? ?????  
#   char c = cvWaitKey(33);  
#   if (c == 27)   
#    break;  
#  }  
#   
#  // ??????? ?? ???????? ??????????? ??????!  
#  cvReleaseCapture( &capture );  
#  cvDestroyWindow(windowName);  
#  return 0;  
# }


# void processFrame(IplImage*& image)  
# {  
#  // ??????????? ????  
#  cvFlip(image,image,1);  
#   
#  // ???????? ????? ???????????  
#  CvSize size = cvSize(image->width, image->height);  
#    
#  // ????? 1 - ?????????? ???????  
#  IplImage* newImage = cvCreateImage(size, image->depth, 1);  
#   
#  // ???????? ??????????? ? ????????? ? grayscale  
#  cvCvtColor(image, newImage, CV_RGB2GRAY);  
#   
#  // ?????????? ????? ???????????  
#  CvRect rect = cvRect(image->width/4,image->height/4,  
#     image->width/2,image->height/2);  
#   
#  // ?????????? region of interest, ??????? ?? ????? ???????  
#  cvSetImageROI(newImage, rect);  
#  cvZero(newImage);  
#  cvResetImageROI(newImage);  
#   
#  // ????????? ???? ???????????  
#  cvNamedWindow("newImage");  
#  cvShowImage("newImage",newImage);  
#   
#  // ?? ?? ????????? ??? ??? ??????? :)  
#  cvReleaseImage(&newImage);  
# }

